*-------------------------------------------------------------------------------
*   Authors: Annekatrin Deglow and Hanne Fjelde
*	Article: Violent Elections and Citizens' Support for Democratic Constraints on the Executive (...)
* 	Journal: Comparative Political Studies
*-------------------------------------------------------------------------------
clear 
log using "ADHF_CPS_replication_logfile", replace
cd "CPS replication/"
use "ADHF_CPS_dataset.dta"
version 17
set more off

// Install coefplot (help coefplpot)
// Install grstyle to replicate graph style (help grstyle)
grstyle init
grstyle set plain
grstyle set ci

*-------------------------------------------------------------------------------
* Section: "Analysis"
*-------------------------------------------------------------------------------
*** Table 1: Average and conditional average treatment effects (OLS)***

// Model 1: ATE 
reg	y_add_5 i.treat_both 
est store M1

// Model 2: CATE
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan 
est store M2

// Model 3: CATE covariate adjusted
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women educated se_gw urb i.ethnicity 
est store M3

// Model 3: Treatment effect for incumbent partisans (not in Table 1, but reported in article)
reg	y_add_5 i.treat_both##i.opp_partisan i.treat_both##i.no_partisan age women educated se_gw urb i.ethnicity 

*-------------------------------------------------------------------------------
*** Figure 1: Conditional average treatment effects ***

// Treatment effect for incumbent supporter
reg	y_add_5 i.treat_both##i.opp_partisan i.treat_both##i.no_partisan 
est store M2b

// Treatment effect for non-partisan
reg	y_add_5 i.treat_both##i.opp_partisan i.treat_both##i.inc_partisan 
est store M2c

// Coefficient plot	
coefplot (M2,  keep(1.treat_both) mcol(black) msymbol(C)  ciopts(lcol(black)) label(Opposition supporter)) ///
		 (M2b, keep(1.treat_both) mcol(black) msymbol(S)  mlcolor(gray*1) mfcolor(gray*1) ciopts(lcol(gray*1))  label(Incumbent supporter)) ///
		 (M2c, keep(1.treat_both) mcol(black) msymbol(T)  mlcolor(gray*0.7) mfcolor(gray*0.7) ciopts(lcol(gray*0.7)) label(No partisan affiliation)), ///
		 levels(95) xline(0, lcolor(red%100) lpatt(dash)) xscale(range(-1.5(0.5)1.5)) xlabel(-1.5(0.5)1.5) ///
		 xtitle("Conditional average treatment effects") title("") ylabel("")		 


*-------------------------------------------------------------------------------
* Sections: "Robustness tests and alternative explanations" + "Supplementary appendix"
*-------------------------------------------------------------------------------
*** Table A1: Summary statistics ***

sort treatment
by treatment: sum y_add_5 age women se_gw urb i.ethnicity 

tab ethnicity treatment

*-------------------------------------------------------------------------------
*** Figure A1: Distribution of item responses ***

foreach x in y_add_5 item1_b item2_b item3_b item4_b item5_b { 
	hist `x', yscale(range(0,200,1000)) ylabel(0(200)1000) lcolor(gray*0.9) fcolor(gray*0.6) freq
} 

*-------------------------------------------------------------------------------
*** Figure A2: Covariate balance ***

mlogit		treatment age women se_gw urb  educated vio_poll lga_non_election_vio state_non_election_vio lga_election_vio state_election_vio i.ethnicity, base(1) 

coefplot  ///
(, keep(*B_TREAT_1*:*) drop(_cons) label(Control vs incumbent threat) msymbol(D) msize(vsmall)  mcol(black) ciopts(lcolor(black))) ///
(, keep(*C_TREAT_2*:*) drop(_cons) label(Control vs opposition threat) msymbol(S) msize(vsmall) mcol(gray*1) ciopts(lcolor(gray*1))) ///
(, keep(*D_TREAT_3*:*) drop(_cons) label(Control vs Boko Haram threat) msize(vsmall) mcol(gray*0.8) ciopts(lcolor(gray*0.8))), ///
levels(95) xline(0, lcolor(red)) legend(rows(3) size(small))  /// 
generate headings(1.ethnicity="{bf:Ethnicity}") 
drop __*

*-------------------------------------------------------------------------------
*** Table A3: Expected values for Y by partisanship and treatment ***

// Bivariate model (Table 1, Model 2)
est restore M2
margins inc_partisan, at(treat_both=(0,1) no_partisan=(0))	
margins, dydx(inc_partisan)  at(treat_both=(0,1) no_partisan=(0))	

// Covariate-adjusted model (Table 1, Model 3)
est restore M3
margins inc_partisan, at(treat_both=(0,1) no_partisan=(0))	
margins, dydx(inc_partisan)  at(treat_both=(0,1) no_partisan=(0))	


*-------------------------------------------------------------------------------
*** Table A4: Conditional average treatment (OLS) effect for non-partisans ***

// Model 1
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.opp_partisan

//Model 2	
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.opp_partisan age women se_gw urb i.ethnicity educated				

*-------------------------------------------------------------------------------	
*** Table A5: Conditional average treatment effects (OLS) for sub-sample ***

// Model 1-2: Incumbent supporters 
reg	y_add_5 i.treat_both if inc_partisan==1 
reg	y_add_5 i.treat_both age women se_gw urb i.ethnicity educated if inc_partisan==1

// Model 3-4: Opposition supporters 
reg	y_add_5 i.treat_both if opp_partisan==1
reg	y_add_5 i.treat_both age women se_gw urb i.ethnicity  educated if opp_partisan==1

// Model 5-6: Non-partisans
reg	y_add_5 i.treat_both if no_partisan==1
reg	y_add_5 i.treat_both age women se_gw urb i.ethnicity  educated if no_partisan==1

*-------------------------------------------------------------------------------
*** Table A6: Conditional average treatment effects (OLS) with PSU-level clustered standard errors and fixed effects *** 

// Model 1: clustered SE
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan, vce(cluster psu)

// Model 3: clustered SE
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women educated se_gw urb i.ethnicity, vce(cluster psu)

// Model 2: PSU FE
xtset psu
xtreg y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan, fe 

// Model 4: PSU FE
xtreg y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women educated se_gw urb i.ethnicity, fe

*-------------------------------------------------------------------------------
*** Table A7: Conditional average treatment effects (OLS) excluding item / item 3 + item 5 *** 

// Model 1: Without item 3, bivariate
reg	y_add_noitem3 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan

// Model 2 Without item 3, covariate adjutsed
reg y_add_noitem3 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women se_gw urb i.ethnicity educated 

// Model 3: Without item 3 + item 5, bivariate
reg	y_add_noitem3_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan 

// Model 4: Without item 3 + item 5, covariate adjusted
reg	y_add_noitem3_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women se_gw urb i.ethnicity educated

*-------------------------------------------------------------------------------
*** Table A8: Factor analysis of outcome items included in the additive index and cronbach's alpha testscale *** 

alpha item1_b item2_b item3_b item4_b item5_b, item
factor item1_b item2_b item3_b item4_b item5_b
rotate 

*-------------------------------------------------------------------------------
*** Table A9: Conditional average treatment effects (OLS) with additional covariates (controlling for election violence) *** 

// Model 1: witnessed violence at polling station
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women se_gw urb i.ethnicity educated vio_poll 

// Model 2: Election violence events at LGA
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women  se_gw urb i.ethnicity educated  lga_election_vio

// Model 3: Election violence events at state
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women  se_gw urb i.ethnicity educated  state_election_vio

*-------------------------------------------------------------------------------
***  Table A10: Average and conditional average treatment effects (OLS), subnational partisanship dynamics *** 

// Model 1
reg	y_add_5 i.treat_both

// Model 2
reg	y_add_5 i.treat_both##i.centralstate  

// Model 3
reg	y_add_5 i.treat_both##i.centralstate age women se_gw urb i.ethnicity educated

*-------------------------------------------------------------------------------
*** Table A11: Average and conditional average treatment effects by threat (OLS) *** 

// Model 1-3: Incumbent-party threat 
reg	y_add_5 i.treat_inc

reg	y_add_5 i.treat_inc##i.inc_partisan i.treat_inc##i.no_partisan

reg	y_add_5 i.treat_inc##i.inc_partisan i.treat_inc##i.no_partisan age women se_gw urb i.ethnicity educated


// Model 4-6: Opposition-party threat
reg	y_add_5 i.treat_opp

reg	y_add_5 i.treat_opp##i.inc_partisan i.treat_opp##i.no_partisan 

reg	y_add_5 i.treat_opp##i.inc_partisan i.treat_opp##i.no_partisan age women se_gw urb i.ethnicity educated
                    

// Model 7-9: Boko Haram threat
reg	y_add_5 i.treat_bh

reg	y_add_5 i.treat_bh##i.inc_partisan i.treat_bh##i.no_partisan 

reg	y_add_5 i.treat_bh##i.inc_partisan i.treat_bh##i.no_partisan age women se_gw urb i.ethnicity educated

*-------------------------------------------------------------------------------
*** Table A12: Security concerns across incumbent-opposition divide *** 

// Item 1 (pre-treatment): How often does competition between political parties lead to violent conflict?
ttest sec_pretreat if no_partisan==0, by(opp_partisan) 

// Item 2a (post-treatment, only use control group): Violence among people in community or village
ttest 	sec_1 if no_partisan==0 & treat_both==0, by(opp_partisan) 

// Item 2b (post-treatment, only use control group): Violence occurring during public protest/march 
ttest 	sec_3 if no_partisan==0 & treat_both==0, by(opp_partisan) 

// Item 2c (post-treatment, only use control group): Violence by political/religious extremist 
ttest 	sec_4 if no_partisan==0 & treat_both==0, by(opp_partisan) 

*-------------------------------------------------------------------------------
*** Table A13: Average and conditional average treatment effects (OLS) with geopolitical zone FE *** 

// Model 1
reg	y_add_5 i.treat_both i.zone 

//Model 2
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan i.zone

// Model 3
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women educated se_gw urb i.ethnicity i.zone

*-------------------------------------------------------------------------------
*** Table A14: Average and conditional average treatment effects (OLS), controlling for non-election related violence *** 

// Model 1:
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women educated se_gw urb i.ethnicity lga_non_election_vio

// Model 2:
reg	y_add_5 i.treat_both##i.inc_partisan i.treat_both##i.no_partisan age women educated se_gw urb i.ethnicity state_non_election_vio

*-------------------------------------------------------------------------------
* Section: "Discussion and external validity"
*-------------------------------------------------------------------------------
clear
use "ADHF_CPS_validation.dta"

*** Table 2: Election violence and non-democratic attitudes: cross-national evidence  ***
 
// Model 1
logit autocrat i.incumbent_partisan##i.violent i.no_partisan##i.violent  male poverty education urban age, cl(ccode)

// Model 2
logit autocrat i.incumbent_partisan##i.violent i.no_partisan##i.violent male poverty education urban age if democracy==0, cl(ccode)

// Model 3
logit autocrat i.incumbent_partisan##i.violent i.no_partisan##i.violent male poverty education urban age if democracy==1, cl(ccode)

*-------------------------------------------------------------------------------
log close


















